﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Simple.Contracts.Contracts;
using Simple.Contracts.Models;
using Simple.Contracts.Models.Common;
using Simple.WebAi.Authorizes;
using System.ComponentModel.DataAnnotations;

namespace Simple.WebAi.Controllers
{
    /// <summary>
    /// 文件
    /// </summary>
    [Route("api/file")]
    [ApiController]
    public class FileController : ControllerBase
    {
        private readonly IFileService _fileService;

        /// <summary>
        /// 依赖注入
        /// </summary>
        /// <param name="fileService"></param>
        public FileController(IFileService fileService)
        {
            _fileService = fileService;
        }

        /// <summary>
        /// 上传图片
        /// </summary>
        /// <param name="fileTag"></param>
        /// <param name="file"></param>
        /// <returns></returns>
        [HttpPost("upload/img")]
        [AccountAuthorize]
        public async Task<Result<UploadImageDto>> UploadImage([FromForm][Required] string fileTag, [FromForm][Required] IFormFile file)
        {
            return await _fileService.UploadImage(fileTag, file);
        }

        /// <summary>
        /// 上传MP3
        /// </summary>
        /// <param name="fileTag"></param>
        /// <param name="durationSecond"></param>
        /// <param name="file"></param>
        /// <returns></returns>
        [HttpPost("upload/mp3")]
        [AccountAuthorize]
        public async Task<Result<UploadMp3Dto>> UploadMp3([FromForm][Required] string fileTag, [FromForm][Required] double durationSecond, [FromForm][Required] IFormFile file)
        {
            return await _fileService.UploadMp3(fileTag, durationSecond, file);
        }
    }
}
